/*
 * @lc app=leetcode.cn id=169 lang=javascript
 *
 * [169] 多数元素
 */

// @lc code=start
/**
 * @param {number[]} nums
 * @return {number}
 */
var majorityElement = function (nums) {
  const target = Math.floor(nums.length / 2);

  let objMap = {};
  for (const value of nums) {
    objMap[value] = (objMap[value] || 0) + 1;
    if (objMap[value] > target) {
      return value;
    }
  }
  return 0;
};
// @lc code=end
